Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cppyy::GetScope to handle nested namespaces and templates #116

Merged

Conversation

Vipul-Cariappa
Copy link
Collaborator

11 new tests pass.
1 xfail, segfaults with this change.

Comment on lines 575 to 576
if (!scope && (parent_scope == nullptr || parent_scope == Cpp::GetGlobalScope()))
scope = Cpp::GetScopeFromCompleteName(name);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about updating

TCppScope_t Cpp::GetScopeFromCompleteName(const std::string &name)

to

TCppScope_t Cpp::GetScopeFromCompleteName(const std::string &name, TCppScope_t parent)

at CppInterOp.

Any suggestions?

Copy link
Collaborator

@aaronj0 aaronj0 Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I think the reason for this interface was to provide the fully scoped name. Do we benefit from providing the parent scope too? (vs using Cpp::GetScope(const std::string &name, TCppScope_t parent))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp::GetScope does not handle namespaces, like my_namespace::my_class.
And Cpp::GetScopeFromCompleteName does not have the parent scope argument.

The code here will be simplified. Thats a benefit.

@aaronj0
Copy link
Collaborator

aaronj0 commented Dec 2, 2024

Looks good! We should probably prevent the seg fault on the xfailing test though.. does it come from the scope lookup or the template instantiation? Maybe a case we can address in clingwrapper/ or whatever calls Cppyy::GetScope in CPyCppyy

@Vipul-Cariappa
Copy link
Collaborator Author

Looks good! We should probably prevent the seg fault on the xfailing test though.. does it come from the scope lookup or the template instantiation? Maybe a case we can address in clingwrapper/ or whatever calls Cppyy::GetScope in CPyCppyy

I suspect it might be after the call to Cppyy::GetScope.

@aaronj0
Copy link
Collaborator

aaronj0 commented Dec 2, 2024

Looks good! We should probably prevent the seg fault on the xfailing test though.. does it come from the scope lookup or the template instantiation? Maybe a case we can address in clingwrapper/ or whatever calls Cppyy::GetScope in CPyCppyy

I suspect it might be after the call to Cppyy::GetScope.

If its after then I guess we are returning the wrong scope

@Vipul-Cariappa
Copy link
Collaborator Author

Vipul-Cariappa commented Dec 3, 2024

Hi @aaronj0. I investigated the failing test.
Test test03_stllike_preinc fails while compiling the following code snippet

namespace __cppyy_internal {
void init_PreIncrement__Iterator(PreIncrement::Iterator*& self, const Token& current) {
  self = new PreIncrement::Iterator{current};
} }

The stack trace goes through Pythonize.cxx:1779.

If I run that single test standalone, it passes.

Performing dump() on the __cppyy_internal namespace I get the following:

With pytest:
Screenshot From 2024-12-03 11-49-01

Running standalone:
Screenshot From 2024-12-03 11-48-42

You can see that the second ParamVarDecl is different.

ping @vgvassilev

EDITED
Reference: compiler-research/CppInterOp#365

Vipul-Cariappa added a commit to Vipul-Cariappa/CppInterOp that referenced this pull request Dec 3, 2024
That needs to be fixed at CppInterOp
reference: look at comments at compiler-research/cppyy-backend#116
@vgvassilev
Copy link
Collaborator

I think it is fine to make it from xfail a crash and investigate later.

Comment on lines 574 to 572
Cppyy::TCppScope_t scope = Cpp::GetScope(name, parent_scope);
if (!scope && (parent_scope == nullptr || parent_scope == Cpp::GetGlobalScope()))
scope = Cpp::GetScopeFromCompleteName(name);
if (scope)
return scope;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cppyy::TCppScope_t scope = Cpp::GetScope(name, parent_scope);
if (!scope && (parent_scope == nullptr || parent_scope == Cpp::GetGlobalScope()))
scope = Cpp::GetScopeFromCompleteName(name);
if (scope)
return scope;
if (Cppyy::TCppScope_t scope = Cpp::GetScope(name, parent_scope))
return scope;
if (!parent_scope || parent_scope == Cpp::GetGlobalScope())
if (Cppyy::TCppScope_t scope = Cpp::GetScopeFromCompleteName(name))
return scope;

You can simplify the code using that pattern...

Comment on lines +581 to +584
Cppyy::TCppScope_t scope = Cpp::GetScope(pure_name, parent_scope);
if (!scope && (!parent_scope || parent_scope == Cpp::GetGlobalScope()))
scope = Cpp::GetScopeFromCompleteName(pure_name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cppyy::TCppScope_t scope = Cpp::GetScope(pure_name, parent_scope);
if (!scope && (!parent_scope || parent_scope == Cpp::GetGlobalScope()))
scope = Cpp::GetScopeFromCompleteName(pure_name);
Cppyy::TCppScope_t scope = Cpp::GetScope(pure_name, parent_scope)
if (scope)
return scope;
if (!parent_scope || parent_scope == Cpp::GetGlobalScope())
scope = Cpp::GetScopeFromCompleteName(pure_name);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not returning the scope here. We are using scope to InstantiateTemplate and returning the template.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok, good point..

@vgvassilev vgvassilev merged commit 33b69db into compiler-research:master Dec 3, 2024
7 of 12 checks passed
Vipul-Cariappa added a commit to Vipul-Cariappa/cppyy-compiler-research that referenced this pull request Dec 3, 2024
Vipul-Cariappa added a commit to Vipul-Cariappa/cppyy-compiler-research that referenced this pull request Dec 3, 2024
Vipul-Cariappa added a commit to Vipul-Cariappa/cppyy-compiler-research that referenced this pull request Dec 3, 2024
vgvassilev pushed a commit to compiler-research/cppyy that referenced this pull request Dec 3, 2024
@Vipul-Cariappa Vipul-Cariappa deleted the dev/update-GetScope branch December 4, 2024 04:55
vgvassilev pushed a commit to faze-geek/CppInterOp that referenced this pull request Dec 19, 2024
That needs to be fixed at CppInterOp
reference: look at comments at compiler-research/cppyy-backend#116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants